package com.wicket.okrframework.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrframework.base.service.MStructureStationGradeService;
import com.wicket.okrframework.base.service.dto.req.QueryPostGradesListReq;
import com.wicket.okrframework.base.service.dto.req.QuerypostGradesDetailReq;
import com.wicket.okrframework.common.dto.FieldInfo;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.dal.mapper.mbg.StructureStationGradeMapper;
import com.wicket.okrframework.dal.po.mbg.StatusCheckItem;
import com.wicket.okrframework.dal.po.mbg.StructureStationGrade;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MStructureStationGradeServiceImpl
        extends ServiceImpl<StructureStationGradeMapper, StructureStationGrade>
        implements MStructureStationGradeService {

    @Autowired
    StructureStationGradeMapper structureStationGradeMapper;

    /**
   * 1-3-02查询岗位等级列表[132]
   */
 @Trace(operationName = "1-3-02查询岗位等级列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<StructureStationGrade>  queryPostGradesList(QueryPostGradesListReq reqDto) {
     
        try {
            QueryWrapper<StructureStationGrade> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(StructureStationGrade.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(StructureStationGrade.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(StructureStationGrade.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByAsc("order_number");
queryWrapper.orderByDesc("operate_time");
            return ((List<StructureStationGrade>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }


    /**
   * 1-3-02删除岗位等级[130]
   */
 @Trace(operationName = "1-3-02删除岗位等级")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  deletepostGrades(String stationGradeId ) {
     
      return super.removeById(stationGradeId);
  }

    /**
   * 1-3-02修改岗位等级[129]
   */
 @Trace(operationName = "1-3-02修改岗位等级")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updatepostGrades(StructureStationGrade structureStationGrade) {
     
        return super.updateById(structureStationGrade);
  }

    /**
   * 1-3-02新增岗位等级[128]
   */
 @Trace(operationName = "1-3-02新增岗位等级")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addpostGrades(StructureStationGrade structureStationGrade) {
     
     if(super.save(structureStationGrade)){
        return structureStationGrade.getStationGradeId();
     }else {
        return "-1";
     }
    
  }

    /**
   * 1-3-02查询岗位等级[131]
   */
 @Trace(operationName = "1-3-02查询岗位等级")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  StructureStationGrade  querypostGradesDetail(QuerypostGradesDetailReq reqDto) {
     
        try {
         
            QueryWrapper<StructureStationGrade> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<StructureStationGrade> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                StructureStationGrade retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
}
